package com.lkx.web;


import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lkx.domain.ApiSubject;
import com.lkx.domain.User;
import com.lkx.service.ApiSubjectService;
import com.lkx.util.PageModule;

@Controller
@RequestMapping("back/apiSubject")
@ResponseBody
public class BackApiSubjectController {

    @Autowired
    private ApiSubjectService apiSubjectService;

    @RequestMapping("list")
    @ResponseBody
    public PageModule list(HttpSession session) {
        PageModule module = new PageModule();
        User user = (User) session.getAttribute("user");
        module = apiSubjectService.list(user.getId());
        return module;
    }

    @RequestMapping("add")
    public PageModule add(HttpSession session, String subjectName) {
        PageModule module = new PageModule();
        User user = (User) session.getAttribute("user");
        ApiSubject model = new ApiSubject();
        model.setUserId(user.getId());
        model.setSubjectName(subjectName);
        int num = apiSubjectService.add(model);
        if (num > 0) {
            module.setStatus(true);
            module.setObject(model.getId());
        }
        return module;
    }

}
